<?php

class myUser extends sfGuardSecurityUser {

    public function getFirstName() {
        return ucwords($this->getGuardUser()->getFirstName());
    }

    public function can_view_doseyeh($dos_id) {
        if (!$this->isAuthenticated())
            return false;

        $this->obj = DosTable::getInstance()->find($dos_id);
        if ($this->obj->getIsFree()) {
            return true;
        }

        $user_id = ($this->getGuardUser()->getId());
        $dos_id = ($dos_id);

//        $raw_sql = <<<EOF
//SELECT
//COUNT(dos.id) as count
//FROM
//dos_user_dos dud,
//
//dos_dos dos
//WHERE 
//dud.user_id = $user_id
//
//AND dos.id = $dos_id
//EOF;
//        $q = Doctrine_Manager::getInstance()->getCurrentConnection();
//        $result = $q->execute($raw_sql);
        $dos = DosTable::getInstance()
                ->createQuery("d")
                ->where('d.id = ?', $dos_id)
                ->fetchArray();
        $courses_id = $dos[0]['course_id'];
        $course = UserDosTable::getInstance()
                ->createQuery("ud")
                ->select("count(ud.id)")
                ->where('ud.user_id = ?', $user_id)
                ->andWhere('ud.course_id=?', $courses_id)
                ->fetchArray();


        return $course[0]['count'] > 0 ? true : false;
    }

}
